package com.zhao.fishingguideserver.mapper;

import com.zhao.fishingguideserver.POJO.CommentLike;
import org.apache.ibatis.annotations.*;

@Mapper
public interface CommentLikeMapper {

    @Insert("INSERT INTO comment_likes(comment_id, user_id) VALUES(#{commentId}, #{userId})")
    int insert(CommentLike commentLike);

    @Delete("DELETE FROM comment_likes WHERE comment_id = #{commentId} AND user_id = #{userId}")
    int deleteByCommentIdAndUserId(@Param("commentId") Integer commentId, @Param("userId") Integer userId);

    @Delete("DELETE FROM comment_likes WHERE comment_id = #{commentId}")
    int deleteByCommentId(@Param("commentId") Integer commentId);

    @Delete("DELETE FROM comment_likes WHERE user_id = #{userId}")
    int deleteByUserId(@Param("userId") Integer userId);

    /**
     * 检查用户是否已点赞评论
     */
    @Select("SELECT COUNT(*) FROM comment_likes WHERE comment_id = #{commentId} AND user_id = #{userId}")
    int checkLike(@Param("commentId") Integer commentId, @Param("userId") Integer userId);

    /**
     * 统计评论的点赞数
     */
    @Select("SELECT COUNT(*) FROM comment_likes WHERE comment_id = #{commentId}")
    int countByCommentId(@Param("commentId") Integer commentId);

    /**
     * 统计用户的评论点赞数
     */
    @Select("SELECT COUNT(*) FROM comment_likes WHERE user_id = #{userId}")
    int countByUserId(@Param("userId") Integer userId);
}
